package ui.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.*;

public class LevelEditor extends JFrame implements ActionListener {

	private ResourceBundle resourceBundle;
	
	private EditPanel pnlSpelbord;
	
	private JTabbedPane tabbedPane;
	private ButtonGroup btnGroup;
	
	private JButton btnExit, btnTerug;
	
	public LevelEditor(ResourceBundle resourceBundle) {
		super("Infected Zone - " + resourceBundle.getString("levelEditor"));
		this.setLayout(new BorderLayout());
		
		this.resourceBundle = resourceBundle;
		
		this.initComponents();
		
		this.addComponents();
		
		this.setSize(500, 500);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	
	private void initComponents() {
		this.pnlSpelbord = new EditPanel();
		
		this.btnGroup = new ButtonGroup();
		
		this.tabbedPane = new JTabbedPane();
		this.tabbedPane.addTab("Obstakels", new JScrollPane(new ObstakelPanel(btnGroup)));
		this.tabbedPane.addTab("Vijanden", new JScrollPane(new VijandenPanel(btnGroup)));
		this.tabbedPane.addTab("Andere", new JScrollPane(new AnderePanel(btnGroup)));
		
		this.btnTerug = new JButton(resourceBundle.getString("terugkeren"));
		this.btnTerug.addActionListener(this);
		this.btnExit = new JButton(resourceBundle.getString("afsluiten"));
		this.btnExit.addActionListener(this);
	}
	
	private void addComponents() {
		JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		pnlSouth.add(btnTerug);
		pnlSouth.add(btnExit);
		
		add(this.tabbedPane, BorderLayout.NORTH);
		add(this.pnlSpelbord, BorderLayout.CENTER);
		add(pnlSouth, BorderLayout.SOUTH);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == this.btnTerug) {
			this.dispose();
			
			KiesSpelbord kiesSpelbord = new KiesSpelbord(this.resourceBundle);
			kiesSpelbord.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}
		else if(e.getSource() == this.btnExit) {
			System.exit(0);
		}
	}
}
